package JDBC;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 执行关联查询
 */
public class JDBCDemo6 {
    public static void main(String[] args) {
        //需求：查看王克晶所带班级的信息，列出：老师的名字，工资，所带班级的名字，楼层
        try (Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();
            String sql = "SELECT t.name,t.salary,c.name,c.floor " +
                    "FROM teacher t " +
                    "JOIN class c ON t.id=c.teacher_id " +
                    "WHERE t.name='王克晶'";
            ResultSet results = statement.executeQuery(sql);
            while (results.next()){
                String name = results.getString("t.name");
                double salary = results.getDouble("t.salary");
                String class_name = results.getString("c.name");
                String floor = results.getString("c.floor");
                //System.out.println(name+","+salary+","+class_name+","+floor);
                String line = String.join(",",name,salary+"",class_name,floor);
                System.out.println(line);
            }

        }catch (Exception e){
            e.printStackTrace();
        }












    }
}
